
#include "FadeEffect.h"

FadeEffect::FadeEffect(RenderableEntity* _entity, float _fDuration, bool _bEnabled, bool _bLoop, float _fInitAlpha, float _fEndAlpha) : SpriteEffect(_entity, _fDuration, _bEnabled, _bLoop)
{
    setParams(_fInitAlpha, _fEndAlpha, true);
}

FadeEffect::FadeEffect(RenderableEntity* _entity, float _fDuration, bool _bEnabled, bool _bLoop, float _fEndAlpha) : SpriteEffect(_entity, _fDuration, _bEnabled, _bLoop)
{
    setParams(0, _fEndAlpha, false);
}

void FadeEffect::updateEffect(float _fPerc)
{
    m_entity->setAlpha(m_fInitAlpha + (m_fEndAlpha - m_fInitAlpha) * _fPerc);
}

void FadeEffect::setParams(float _fInitAlpha, float _fEndAlpha, bool _bHasInit)
{
    m_fInitAlpha = _fInitAlpha;
    m_fEndAlpha = _fEndAlpha;
    m_bHasInit = _bHasInit;
}

void FadeEffect::enableEffect(bool _bValue)
{
	if(_bValue && !m_bHasInit)
	{
		m_fInitAlpha = m_entity->getAlpha();
	}
}
